<?php

/**
 * BonEntre filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseBonEntreFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'reference'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'date_creation'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'date_validite'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'fournisseur_id'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Fournisseur'), 'add_empty' => true)),
      'departement_destination_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('DepartementDestination'), 'add_empty' => true)),
      'magasinie_id'               => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Employe'), 'add_empty' => true)),
      'observation'                => new sfWidgetFormFilterInput(),
      'confirme'                   => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'valider'                    => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'etat_reglement'             => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'livre'                      => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'cloture'                    => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'reference_bon_livraison'    => new sfWidgetFormFilterInput(),
      'created_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'deleted_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'm_stock_article_list'       => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle')),
    ));

    $this->setValidators(array(
      'reference'                  => new sfValidatorPass(array('required' => false)),
      'date_creation'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'date_validite'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'fournisseur_id'             => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Fournisseur'), 'column' => 'id')),
      'departement_destination_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('DepartementDestination'), 'column' => 'id')),
      'magasinie_id'               => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Employe'), 'column' => 'id')),
      'observation'                => new sfValidatorPass(array('required' => false)),
      'confirme'                   => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'valider'                    => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'etat_reglement'             => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'livre'                      => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'cloture'                    => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'reference_bon_livraison'    => new sfValidatorPass(array('required' => false)),
      'created_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'deleted_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'm_stock_article_list'       => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('bon_entre_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMStockArticleListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonEntre LigneBonEntre')
      ->andWhereIn('LigneBonEntre.stock_article_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'BonEntre';
  }

  public function getFields()
  {
    return array(
      'id'                         => 'Number',
      'reference'                  => 'Text',
      'date_creation'              => 'Date',
      'date_validite'              => 'Date',
      'fournisseur_id'             => 'ForeignKey',
      'departement_destination_id' => 'ForeignKey',
      'magasinie_id'               => 'ForeignKey',
      'observation'                => 'Text',
      'confirme'                   => 'Boolean',
      'valider'                    => 'Boolean',
      'etat_reglement'             => 'Boolean',
      'livre'                      => 'Boolean',
      'cloture'                    => 'Boolean',
      'reference_bon_livraison'    => 'Text',
      'created_at'                 => 'Date',
      'updated_at'                 => 'Date',
      'deleted_at'                 => 'Date',
      'm_stock_article_list'       => 'ManyKey',
    );
  }
}
